home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 756 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: clamage@Eng.Sun.COM (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: enums and conversion question
  5. Date: 18 Mar 1996 09:45:00 PST
  6. Organization: Sun Microsystems Inc., Mountain View, CA
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4ihe7k$1cu@engnews1.Eng.Sun.COM>
  9. References: <4icihu$e3d@nrchh52.rich.nt.com>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 17 Mar 1996 16:22:12 GMT
  12. X-Newsreader: NN version 6.5.0 #21 (NOV)
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMU2hd0y4NqrwXLNJAQGlXAIAmkl4i2IY79diEM+rgBiZsIhWG8qXoWl+
  15.     A76mS0uV8OZmZo3hBQijx0TQZZV5ql3+q+O2RV7WkIkshuBI9kneDg==
  16.     =5afj
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. raviyer@nt.com writes:
  20.  
  21. >void goo(int);
  22. >void goo(unsigned int);
  23.  
  24. >enum Enum {E1,E2}
  25.  
  26. >void foo ()
  27. >{
  28. >    Enum e = E1;
  29. >    goo(e); // Is this call ambiguos?
  30. >}
  31.  
  32. >The DWP in 4.5 (integral promotion) point 2 says that 
  33. >"An rvalue of type wchar_t or an enumeration type can be converted to an
  34. >rvalue of the _first_ of the following types that can represent all the values
  35. >of the source type: int, unsigned int, long, unsigned long."
  36.  
  37. >Does this mean that in the above example the call to goo(e) should be resolved
  38. >to goo(int)? or in other words is the promotion enum -> int better than 
  39. >enum -> unsigned int in this case?
  40.  
  41. Yes, although your "other words" are not quite correct.
  42.  
  43. If the range of an enum type can be represented by type int, values
  44. of that type undergo promotion to int, and not to any other type.
  45. Thus, calling goo(int) requires only a promotion to int (since the
  46. values 0 and 1 can always be represented by type int), while calling
  47. goo(unsigned int) requires a standard conversion. A promotion is
  48. preferred over a conversion, so the call is not ambiguous.
  49.  
  50. --
  51. Steve Clamage, stephen.clamage@eng.sun.com
  52. ---
  53. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  54.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  55.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  56.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  57.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  58. ]
  59.